package git.soulbgm.controller;

import git.soulbgm.pojo.ServiceRunningStatus;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

import java.lang.management.ManagementFactory;

/**
 * 监控控制器
 *
 * @author SoulBGM
 * @date 2020-11-18 10:03:05
 */
@RestController
public class MonitorController {

    /**
     * 心跳接口
     *
     * @return up
     */
    @GetMapping("heartbeat")
    public ServiceRunningStatus heartbeat() {
        ServiceRunningStatus status = new ServiceRunningStatus();
        status.setStatus("up");
        long startTime = ManagementFactory.getRuntimeMXBean().getStartTime();
        status.setStartupTime(startTime);
        status.setRunningTime(System.currentTimeMillis() - startTime);
        return status;
    }

}
